﻿using System;
using ch.froorider.NGoogleCalendar.googleService;
using ch.froorider.NGoogleCalendar.tools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NGoogleCalendarTests
{
    
    
    /// <summary>
    ///This is a test class for GoogleAccountTest and is intended
    ///to contain all GoogleAccountTest Unit Tests
    ///</summary>
    [TestClass]
    public class GoogleAccountTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for GoogleAccount Constructor
        ///</summary>
        [TestMethod]
        public void GoogleAccountConstructorTest()
        {
            string accountName = "sharp.calendar@gmail.com";
            string pass = "ngooglecalendar";
            GoogleAccount target;
            
            //1. we test if we can access the existing account
            try
            {
                target = new GoogleAccount(accountName, pass);
                Assert.IsInstanceOfType(target, typeof(GoogleAccount));
            }
            catch (NGoogleCalendarException ae)
            {
                Assert.Fail("Exception caught: " + ae.Message);
            }
            
            //2. Negativ logic -> a wrong account name should throw an excpetion
            try
            {
                accountName = "foo@bar.com";
                new GoogleAccount(accountName, pass);
                Assert.Fail("An ApplicationException should be raised.");
            }
			catch (NGoogleCalendarException ae)
            {
                Console.WriteLine("Expected exception caught: " + ae.Message);
            }

            //3. Negativ logic -> a wrong pass should throw an excpetion
            try
            {
                accountName = "sharp.calendar@gmail.com";
                pass = "bullshit";
                new GoogleAccount(accountName, pass);
                Assert.Fail("An ApplicationException should be raised.");
            }
			catch (NGoogleCalendarException ae)
            {
                Console.WriteLine("Expected exception caught: " + ae.Message);
            }
        }


        /// <summary>
        ///A test for verifyAccount
        ///</summary>
        [TestMethod]
        [Ignore]
        public void verifyAccountTest()
        {
            
        }
    }
}
